package com.pactera.controller.common.api;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.pactera.common.utils.JsonResponseUtils;
import com.pactera.vo.common.BaseRespVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "AdminDebugApi")
@RestController
@RequestMapping("/api/debug")
public class AdminDebugApi {

	@ApiOperation(value = "设置session", notes = "设置session")
	@RequestMapping(value = "/setSession", method = RequestMethod.POST)
	public BaseRespVo setSession(HttpServletRequest request) throws Exception {
		request.getSession().setAttribute("requestUrl", request.getRequestURL());
		
		Map<String, Object> map = new HashMap<>();
		map.put("requestUrl", request.getRequestURL());
		
		
		return JsonResponseUtils.successData(BaseRespVo.class, map);
	}

	@ApiOperation(value = "获取session", notes = "获取session")
	@RequestMapping(value = "/getSession", method = RequestMethod.POST)
	public BaseRespVo getSession(HttpServletRequest request) throws Exception {

		Map<String, Object> map = new HashMap<>();
		map.put("sessionId", request.getSession().getId());
		map.put("message", request.getSession().getAttribute("requestUrl"));

		return JsonResponseUtils.successData(BaseRespVo.class, map);
	}
}
